﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;

namespace LI4.Presentation
{
    public partial class MenuRegistos : Form
    {
        public ArrayList topRegs;

        public MenuRegistos()
        {
            InitializeComponent();
        }

        private void MenuRegistos_Load(object sender, EventArgs e)
        {
            Data.Registos dataReg = new LI4.Data.Registos();

            topRegs = dataReg.getLastRegs();

            string[] row = new string[3];

            foreach (Business.Registo reg in topRegs)
            {
                row[0]= reg.Username;
                row[1]=reg.Descricao;
                row[2] = reg.Data;
                registosT.Rows.Add(row);
            }
        }

        private void MenuRegistos_Shown(object sender, EventArgs e)
        {
            procuraTB.Focus();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string palavrac = procuraTB.Text.Trim();
            Data.Registos dataR = new LI4.Data.Registos();

            ArrayList regs = dataR.getRegistosPC(palavrac);

            if (regs.Count > 0)
            {
                registosT.Rows.Clear();
                string[] row = new string[3];

                foreach (Business.Registo reg in regs)
                {
                    row[0] = reg.Username;
                    row[1] = reg.Descricao;
                    row[2] = reg.Data;
                    registosT.Rows.Add(row);
                }
            }
            else
            {
                registosT.Rows.Clear();
                MessageBox.Show(this, "Não foi encontrado nenhum resultado.\nTente novamente!", "Pesquisa.", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                procuraTB.Text = "";
            }
        }
    }
}
